# -*- coding: latin-1 -*-
import unittest
from compras.models import *
from productos.models import Producto
from contactos.models import Contacto
from django.test.client import Client
from datetime import *


class SimpleTest(unittest.TestCase):
    #fixtures = ['/fixtures/initial_data.json',]
    def setUp(self):
        # Every test needs a client.
        self.client = Client()

    def test_view(self):
	response = self.client.get('/gestion/admin/compras/compra/')
	self.failUnlessEqual(response.status_code, 200)
	response = self.client.post('/gestion/admin/login/', {'username': 'gonzalo', 'password': 'Greenday7'})
	self.failUnlessEqual(response.status_code, 200)

	response = self.client.login(username='gonzalo', password='Greenday7')
        ## Check that the respose is 200 OK.
	#print response
        #self.failUnlessEqual(response, True)
    def test_sacar_moneda(self):
	self.failUnlessEqual(sacar_moneda("$ 2.5"),2.5)
	self.failIfEqual(sacar_moneda("$ 2.2"),2.5)
	self.failUnlessEqual(sacar_moneda("u$s 2.5"),2.5)
	self.failIfEqual(sacar_moneda("u$s 2.2"),2.5)


class ItemTestCase(unittest.TestCase):
    fixtures = ['initial_data.json',]
    def setUp(self):
	contacto= Proveedor.objects.all()[0]
        self.compra = Compra.objects.create(neto= 7922, iva= 1663.62,remito= "234223", cotizacion= 1.0, fecha= datetime.today().date(), comprobante= "232423",proveedor=contacto, pagado= 300, bruto= 7922, saldo= 9285.62, cuit= "20312177529", efectivo= 100.0, total= 9585.62,  domicilio= "pehuajo")
	produc= Producto.objects.get(id=1)
	self.item = ItemCompra.objects.create(cantidad= 34.0,producto= produc,compra= self.compra,unidad_medida= "kilo",precio_unitario= "$ 233.0",importe= "$ 7922.0",moneda_id=1) 
	
    def testCreating(self):
	    pass
	#self.failUnlessEqual(self.item.precio_unitario_en_pesos(),233.0)
	#self.failIfEqual(self.item.precio_unitario_en_pesos(),243.0)
	#self.failUnlessEqual(self.item.importe_en_pesos(),7922.0)
	#self.failIfEqual(self.item.importe_en_pesos(),7932.0)
	